package my.edu.utils;

import my.edu.model.information.entity.OperationLog;

public class ThreadLocalUtil {

    // 使用 ThreadLocal 来存储每个线程的 OperationLog 实例
    private static final ThreadLocal<OperationLog> operationLogThreadLocal = ThreadLocal.withInitial(OperationLog::new);

    // 获取当前线程的 OperationLog 实例
    public static OperationLog getOperationLog() {
        return operationLogThreadLocal.get();
    }

    // 设置当前线程的 OperationLog 实例
    public static void setOperationLog(OperationLog operationLog) {
        operationLogThreadLocal.set(operationLog);
    }

    // 清理 ThreadLocal 变量
    public static void removeOperationLog() {
        operationLogThreadLocal.remove();
    }

//    // 使用 ThreadLocal 来存储每个线程的 id
    public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void setCurrentId(Long id) {
        threadLocal.set(id);
    }

    public static Long getCurrentId() {
        return threadLocal.get();
    }

    public static void removeCurrentId() {
        threadLocal.remove();
    }


}